define(['common/js/boss-frame-angular-dev-0.1'],function(){
	diretiveModule.directive('plusDisplayData', function() {
		return {
			scope : false,
			restrict : "E",
			replace : true,
			transclude : true,
			compile : function(tElm,tAttrs){
				if(!tAttrs.data || ! tAttrs.columnDefs){
					console.error("请指定属性data column-defs");
					return;
				}

				return {
					pre:function($scope,elem,attrs){
						//初始化数据
						var _data = attrs.data,
							_direction = attrs.titleDirection,
							_defs = attrs.columnDefs;
						$scope.fColumnDefs = $scope[_defs];
						$scope.fData = $scope[_data];

						$scope.$watch(_data, function (newVal, oldVal) {
							if (newVal !== oldVal) {
								if(!angular.isArray($scope.fData)){
									$scope.fData = $scope[_data];
								}
							}
						}, true);

						//展示类型 1.竖直单值 2.水平单值 3.水平列表
						$scope.displayType = 2;

						//如果未指定columnDefs
						if(!$scope.fColumnDefs){
							$scope.fColumnDefs = [];
							for(var field in $scope.fData){
								$scope.fColumnDefs.push({
									field : field
								});
							}
						}

						$scope.displayType = _direction=="vertical"?1:2;
						if(angular.isArray($scope.fData)){
							$scope.displayType = 3;
						}
					}
				};
			},
			templateUrl:"common/js/html/plusDisplayData.html"
		};
	});

	diretiveModule.directive('displayCell', function ($compile) {
		return {
			scope: false,
			restrict: "AE",
			link : function (scope, elm, attrs) {

				var html = scope.column.cellTemplate;

				var entityStr = "entity";
				if(!scope.entity){
					entityStr = "fData";
				}

				if (!html) {
					html = entityStr+"." + scope.column.field;

					if (scope.column.cellFilter) {
						html += "|" + scope.column.cellFilter
					}

					html = "<span>{{" + html + "}}</span>";
				} else {
					if (typeof html == "function") {
						html = html(scope[entityStr], scope.column);
					}
				}

				var cellElement = $('<tmp>'+html+'</tmp>');
				elm.append(cellElement);
				$compile(cellElement)(scope);
			}
		};
	});
});